package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.service.RoomMarkService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/roomMark")
public class RoomMarkController {

    @Resource
    private RoomMarkService roomMarkService;

    @GetMapping("/findAll")
    public Result<?> findAll(@RequestParam(defaultValue = "0") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             @RequestParam(defaultValue = "") String search) {
        PageInfo roomMarkpage = roomMarkService.findAll(pageNum, pageSize, search);
        if (roomMarkpage != null) {
            return Result.success(roomMarkpage);
        } else {
            return Result.error("-1", "查询失败");
        }
    }


    /**
     * 更新学生信息
     */
    @GetMapping("/update")
    public Result<?> update(@RequestParam int dormroomId,
                            @RequestParam String score,
                            @RequestParam String text) {

        int i = roomMarkService.updateroomMark(dormroomId, score, text);
        if (i == 1) {
            return Result.success();
        } else {
            return Result.error("-1", "更新失败");
        }
    }
}
